using BlawkayEngine;
using BlawkayEngine.ScreenSystem;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Input;

namespace BlawkayHockey
{

    public class GameManager : Game
    {

        #region Constructor

        public GameManager()
        {
            _GraphicsDeviceManager = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            _GraphicsDeviceManager.PreferredBackBufferWidth = 1280;
            _GraphicsDeviceManager.PreferredBackBufferHeight = 720;

            Components.Add(new GamerServicesComponent(this));
        }

        #endregion

        #region Main Methods

        protected override void Initialize()
        {
            base.Initialize();
        }

        protected override void LoadContent()
        {
            GameInfo.LoadAll(this);
            GameInfo.ScreenManager = new HomeMenuManager(this);
        }

        protected override void UnloadContent()
        {

        }

        protected override void Update(GameTime gameTime)
        {
            if (Guide.IsVisible == false && SignedInGamer.SignedInGamers.Count == 0)
            {
                Guide.ShowSignIn(1, false);
            }

            GameInfo.BeginUpdate();
            GameInfo.GameTime = gameTime;

            if (GameInfo.KeyboardInput.JustPressed(Keys.D))
            {
                GameInfo.IsDebug = !GameInfo.IsDebug;
            }

            if (GameInfo.KeyboardInput.JustPressed(Keys.Escape))
            {
                this.Exit();
            }

            if (Networking.IsSessionRunning)
                Networking.Session.Update();

            GameInfo.ScreenManagerUpdate();

            GameInfo.EndUpdate();
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GameInfo.BeginDraw();

            GameInfo.ScreenManager.Draw();

            

            GameInfo.EndDraw();
            base.Draw(gameTime);
        }

        #endregion

        #region Fields

        GraphicsDeviceManager _GraphicsDeviceManager;

        #endregion

    }

    #region Entry Point

#if WINDOWS || XBOX
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            using (GameManager game = new GameManager())
            {
                game.Run();
            }
        }
    }
#endif

    #endregion

}
